{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5e85aaa7-6782-4629-84e0-71a6b7eaa505", "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'\n", "\n", "import warnings \n", "warnings.filterwarnings(\"ignore\") #ignore some matplotlib warnings\n", "\n", "import numpy as np\n", "\n", "from mpi4py import MPI\n", "\n", "from triqs.plot.mpl_interface import plt, oplot, oplotr, oploti\n", "plt.rcParams[\"figure.figsize\"] = (6,4) # set default size for all figures" ] }, { "cell_type": "markdown", "id": "e51b0091-8880-4691-9ad1-7cddcff025bd", "metadata": {}, "source": [ "# Step-by-step guide" ] }, { "cell_type": "markdown", "id": "aa879df5-ca9d-45fa-ae03-988074b80939", "metadata": {}, "source": [ "## Step 1 - Spawn solver instance\n", "\n", "The first step in using `soehyb` is to instantiate an instance of the `triqs_soehyb.Solver` class." ] }, { "cell_type": "code", "execution_count": 2, "id": "a210740f-d7db-4017-a81b-7ccd915f8758", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Warning: could not identify MPI environment!\n", " ___ ___ _ ___ _____\n", " / __| ___| __|__| || \\ \\ / / _ )\n", " \\__ \\/ _ \\ _|___| __ |\\ V /| _ \\\n", " |___/\\___/___| |_||_| |_| |___/ [github.com/TRIQS/soehyb]\n", "\n", "beta = 5.0, lamb = 2.50E+02, eps = 1.00E-08, N_DLR = 32\n", "fundamental_operators = [1*c('up',0), 1*c('up',1), 1*c('up',2), 1*c('do',0), 1*c('do',1), 1*c('do',2)]\n", "H_mat.shape = (64, 64)\n", "H_loc = 0\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Starting serial run at: 2025-08-19 11:38:46.470781\n" ] } ], "source": [ "from triqs_soehyb import Solver \n", "\n", "norb = 3\n", "\n", "S = Solver(\n", " beta=5.0, \n", " gf_struct=[('up', norb), ('do', norb)], \n", " eps=1e-8, w_max=50.0)" ] }, { "cell_type": "markdown", "id": "8b4605f0-84d6-493b-a012-688506faf2c1", "metadata": {}, "source": [ "The solver constructor takes the input\n", "\n", "- `beta`: inverse temperature\n", "- `gf_struct`: Green's function structure 1st index: name, 2nd index: dimension of subspace\n", "- `eps`: Accuracy of Discrete Lehmann Representation (DLR) used for imaginary time response functions\n", "- `w_max`: DLR freqiency cut-off (the spectrum of the model must be in the range `[-w_max, +w_max]`" ] }, { "cell_type": "markdown", "id": "549bb71a-f72c-47a5-9ba0-1f512be65465", "metadata": {}, "source": [ "## Step 2 - Impurity many-body Hamiltonian\n", "\n", "We also have to construct the local many-body Hamiltonian (`h_int`) of the Anderson impurity model we want to solve." ] }, { "cell_type": "markdown", "id": "534105f9-15b8-4631-af12-336fcfa9470e", "metadata": {}, "source": [ "### Examples\n", "\n", "- For the **single band Hubbard model** the interaction is density-density only and can be constructed using the Triqs second-quantization operators found in `triqs.operators.*`." ] }, { "cell_type": "code", "execution_count": 3, "id": "a1eac349-5da2-4675-9659-417357d3d0f7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-1*c_dag('do',0)*c('do',0) + -1*c_dag('up',0)*c('up',0) + 2*c_dag('do',0)*c_dag('up',0)*c('up',0)*c('do',0)\n" ] } ], "source": [ "from triqs.operators import n\n", "\n", "U = 2.0\n", "mu = U / 2 # Chemical potential for half-filling\n", "h_int = U * n('up',0) * n('do', 0) - mu * ( n('up', 0) + n('do', 0) )\n", "\n", "print(h_int)" ] }, { "cell_type": "markdown", "id": "dedae90a-a720-47cf-b67c-5ae4482bf198", "metadata": {}, "source": [ "- For multi-orbital models one often use the **Kanamori interaction** which can be built using tools in `triqs.operators.util.*` as follows." ] }, { "cell_type": "code", "execution_count": 4, "id": "f55b959b-4469-46d7-9d95-336acdc14e05", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.2*c_dag('do',0)*c_dag('do',1)*c('do',1)*c('do',0) + 2.2*c_dag('do',0)*c_dag('do',2)*c('do',2)*c('do',0) + 0.8*c_dag('do',0)*c_dag('up',0)*c('up',2)*c('do',2) + 0.8*c_dag('do',0)*c_dag('up',0)*c('up',1)*c('do',1) + 4.6*c_dag('do',0)*c_dag('up',0)*c('up',0)*c('do',0) + 3*c_dag('do',0)*c_dag('up',1)*c('up',1)*c('do',0) + 0.8*c_dag('do',0)*c_dag('up',1)*c('up',0)*c('do',1) + 3*c_dag('do',0)*c_dag('up',2)*c('up',2)*c('do',0) + 0.8*c_dag('do',0)*c_dag('up',2)*c('up',0)*c('do',2) + 2.2*c_dag('do',1)*c_dag('do',2)*c('do',2)*c('do',1) + 0.8*c_dag('do',1)*c_dag('up',0)*c('up',1)*c('do',0) + 3*c_dag('do',1)*c_dag('up',0)*c('up',0)*c('do',1) + 0.8*c_dag('do',1)*c_dag('up',1)*c('up',2)*c('do',2) + 4.6*c_dag('do',1)*c_dag('up',1)*c('up',1)*c('do',1) + 0.8*c_dag('do',1)*c_dag('up',1)*c('up',0)*c('do',0) + 3*c_dag('do',1)*c_dag('up',2)*c('up',2)*c('do',1) + 0.8*c_dag('do',1)*c_dag('up',2)*c('up',1)*c('do',2) + 0.8*c_dag('do',2)*c_dag('up',0)*c('up',2)*c('do',0) + 3*c_dag('do',2)*c_dag('up',0)*c('up',0)*c('do',2) + 0.8*c_dag('do',2)*c_dag('up',1)*c('up',2)*c('do',1) + 3*c_dag('do',2)*c_dag('up',1)*c('up',1)*c('do',2) + 4.6*c_dag('do',2)*c_dag('up',2)*c('up',2)*c('do',2) + 0.8*c_dag('do',2)*c_dag('up',2)*c('up',1)*c('do',1) + 0.8*c_dag('do',2)*c_dag('up',2)*c('up',0)*c('do',0) + 2.2*c_dag('up',0)*c_dag('up',1)*c('up',1)*c('up',0) + 2.2*c_dag('up',0)*c_dag('up',2)*c('up',2)*c('up',0) + 2.2*c_dag('up',1)*c_dag('up',2)*c('up',2)*c('up',1)\n" ] } ], "source": [ "spin_names = ['up', 'do']\n", "\n", "U = 4.6\n", "J = 0.8\n", "\n", "from triqs.operators.util.U_matrix import U_matrix_kanamori\n", "\n", "KanMat1, KanMat2 = U_matrix_kanamori(norb, U, J)\n", "\n", "from triqs.operators.util.hamiltonians import h_int_kanamori\n", "\n", "h_int = h_int_kanamori(spin_names, norb, KanMat1, KanMat2, J, off_diag=True)\n", "\n", "print(h_int)\n", "\n", "from itertools import product\n", "N = sum([ n(spin, idx) for spin, idx in product(spin_names, range(norb)) ])\n", "\n", "mu = 0.5*(5*U - 10*J)\n", "\n", "h_int -= mu * N" ] }, { "cell_type": "markdown", "id": "378098ff-7233-4434-9bec-9b75a31c6342", "metadata": {}, "source": [ "## Step 3 - Hybridization function\n", "\n", "To fully specify the Anderson impurity model we also have to supply the hybridization function $\\Delta(\\tau)$ that describes the retarded fluctuation of electrons to the environment. The solver instance `S` sets up the hybridization function container available as `S.Delta_tau` and we need to explicitly set its value." ] }, { "cell_type": "markdown", "id": "ff8a13fd-5eeb-46d1-9d5d-bf30825cf4af", "metadata": {}, "source": [ "### Examples\n", "\n", "Here is a simple example with a Hybridization function $\\Delta(\\tau)$ comprised of a **single discrete pole/state**." ] }, { "cell_type": "code", "execution_count": 5, "id": "0ada854e-a4b4-491c-afbd-5540c6d91a25", "metadata": {}, "outputs": [], "source": [ "from triqs.gf import make_gf_dlr_imtime, make_gf_dlr_imfreq\n", "from triqs.gf import inverse, iOmega_n\n", "\n", "for bidx, delta_tau in S.Delta_tau:\n", " delta_w = make_gf_dlr_imfreq(delta_tau)\n", " delta_w << inverse(iOmega_n - 1.0)\n", " delta_tau[:] = make_gf_dlr_imtime(delta_w)" ] }, { "cell_type": "markdown", "id": "7ecac644-9fb2-43c0-b53d-8b26f055db75", "metadata": {}, "source": [ "Another common test case is a spin- and orbital-diagonal hybridzation function with a **semi-circular density of states**." ] }, { "cell_type": "code", "execution_count": 6, "id": "d2e4b357-677c-4238-a60a-dc3497f16648", "metadata": {}, "outputs": [], "source": [ "from triqs.gf import make_gf_dlr_imtime, make_gf_dlr_imfreq, SemiCircular\n", "\n", "for bidx, delta_tau in S.Delta_tau:\n", " delta_w = make_gf_dlr_imfreq(delta_tau)\n", " delta_w << SemiCircular(2.0)\n", " delta_tau[:] = make_gf_dlr_imtime(delta_w)" ] }, { "cell_type": "markdown", "id": "27ec122a-487d-490f-9762-16236168f559", "metadata": {}, "source": [ "## Step 4 - Self-consistent solution\n", "\n", "Combining the hybridization fucntion `S.Delta_tau` and the local many-body interaction `h_int` the Anderson impurity model is fully specified and we can call the `S.solve(...)` method to obtain the pseudo-particle self-consistent solution at a given expansion `order`." ] }, { "cell_type": "code", "execution_count": 7, "id": "e7c57247-8d19-4244-a16e-d9096bc3ea82", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AdaPol: Hybridization fit accuracy 1.31E-07, using 5 poles.\n", "(Order, N_Diags) = [(1, 1), (2, 60)]\n", "max_order = 2\n", "\n", " iter | conv | Z-1 \n", "------+----------+-----------\n", " 1 | 1.95E-01 | +2.22E-16\n", " 2 | 3.68E-02 | +1.11E-15\n", " 3 | 2.64E-02 | +2.22E-16\n", " 4 | 3.25E-03 | -3.33E-16\n", " 5 | 1.83E-03 | -2.22E-16\n", " 6 | 6.63E-04 | +2.22E-16\n", " 7 | 6.22E-05 | +2.22E-16\n", " 8 | 6.54E-05 | -9.99E-16\n", " 9 | 1.34E-05 | +2.22E-16\n", " 10 | 3.23E-06 | +0.00E+00\n", "\n", "Timing: incl. excl.\n", "------------------------------------------------------------\n", "Dyson equation: 17.747 17.747 8.5% |--|\n", "Hybridization compression (AAA): 0.245 0.245 0.1% |\n", "Pseudo-particle self-energy: 171.026 171.026 82.3% |--------------------------------|\n", "Single particle Green's function: 15.046 15.046 7.2% |--|\n", "Other: 3.631 3.631 1.7% ||\n", "------------------------------------------------------------\n", "Total: 207.696 100.0%\n", "\n" ] } ], "source": [ "S.solve(h_int=h_int, order=2)" ] }, { "cell_type": "markdown", "id": "bba188a4-d19d-477f-bdf0-b135f5c5d01a", "metadata": {}, "source": [ "## Step 5 - Single particle response function\n", "\n", "After convergence the solver computes the diagrammatic series for the single particle Green's function that is available as the member `S.G_tau` of the solver class instance `S`." ] }, { "cell_type": "code", "execution_count": 8, "id": "eeb420d4-fc66-436b-8f4a-483f35715ded", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Green Function G composed of 2 blocks: \n", " Greens Function G_up with mesh DLR imaginary time mesh of size 32 with beta = 5, statistics = Fermion, w_max = 50, eps = 1e-08 and target_shape (3, 3): \n", " \n", " Greens Function G_do with mesh DLR imaginary time mesh of size 32 with beta = 5, statistics = Fermion, w_max = 50, eps = 1e-08 and target_shape (3, 3): \n", " \n", "\n" ] } ], "source": [ "print(S.G_tau)" ] }, { "cell_type": "markdown", "id": "83a9a807-d760-424b-a80f-1cb2c66ff1d0", "metadata": {}, "source": [ "## Step 6 - Store solver to disk\n", "\n", "The solver is hdf5 serializable and can be written to disk using the `h5` module." ] }, { "cell_type": "code", "execution_count": 9, "id": "76b80b13-05a5-49c1-ae86-ed868d5c693a", "metadata": {}, "outputs": [], "source": [ "from h5 import HDFArchive\n", "\n", "filename = f'data_soehyb_result.h5'\n", "with HDFArchive(filename, 'w') as A: \n", " A['S'] = S" ] }, { "cell_type": "markdown", "id": "b7c6ef11-3bcc-43d5-892e-f08389329da0", "metadata": {}, "source": [ "## Step 7 - Read result from disk\n", "\n", "For later visualization we can now read the solver and its data from disk." ] }, { "cell_type": "code", "execution_count": 10, "id": "477ab542-bd45-4aa8-b3d2-1851e7d5ce3d", "metadata": {}, "outputs": [], "source": [ "with HDFArchive(filename, 'r') as A:\n", " S = A['S']" ] }, { "cell_type": "markdown", "id": "c493ba7c-f201-467c-aa05-87cbe9b23db4", "metadata": {}, "source": [ "## Step 7 - Postprocessing and visualization \n", "\n", "The single particle Green's function can now be visualized using the standard Triqs plotting tools." ] }, { "cell_type": "code", "execution_count": 11, "id": "f202ea70-e583-4e8c-bb8d-6cf3564ad5fe", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", " \n", " 2025-08-19T11:42:14.759884\n", " image/svg+xml\n", " \n", " \n", " Matplotlib v3.10.3, https://matplotlib.org/\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from triqs.plot.mpl_interface import plt, oplot, oplotr, oploti\n", "\n", "oplotr(S.G_tau['up'][0, 0], label=None)\n", "plt.ylabel(r'$G(\\tau)$');" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.17" } }, "nbformat": 4, "nbformat_minor": 5 }